package com.smforj.ssm.modules.sys.util;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.smforj.ssm.modules.lib.constant.LibType;

/***
 * 工具对象生成工厂类
 * 可以会对不能类型生成不同对象
 * 
 * @author Haijun Gao 
 * @date 2017-4-28 下午2:08:31
 * @desp http://www.cnblogs.com/saga5998/
 * @email 573107773@qq.com
 */
public class UtilFactory {  
	
	/***
	 * 线程安全
	 */
	private static final Map<LibType,ISip2Msg> map = new ConcurrentHashMap<LibType,ISip2Msg>();
	
	/***
	 * 获取或生成对象
	 * @param key
	 * @return
	 * @date 2017-4-28 下午2:46:29
	 */
	private static ISip2Msg getOrCreateSip2Msg(LibType key)
	{ 
		if(map.containsKey(key))
			return map.get(key);
		else
		{
			ISip2Msg msg = null;
			switch(key)
			{
				case GDLISNET:
					msg = new SIP2MsgGdlis();
					break;
				case BEIDAQINGYANG:
					msg = new SIP2MsgQingyang();
					break; 
				case ES:
					msg = new SIP2MsgGdlis();
					break;
				default:
					msg = new SIP2MsgGdlis();
					break;
					
			}
			map.put(key, msg);
			return msg;
		}
		
	}
	/***
	 * 获取sip2消息处理接口
	 * @param type
	 * @return
	 * @date 2017-4-28 下午2:47:07
	 */
	public static ISip2Msg getSip2(LibType type)
	{  
		return getOrCreateSip2Msg(type);
	}
}
